﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LAVAA.DAL
{
    public class UnitOfWork : IDisposable
    {
        private LavaaEntitiesConnection _context = new LavaaEntitiesConnection();
        private ActivityRepository _actRep;
        private RewardTypeRepository _rewRep;
        private ActivityTypeRepository _actTypeRep;
        private UserRepository _usrRep;
        private UserGroupRepository _usrGrpRep;

        public ActivityRepository ActivityRepository
        {
            get
            {
                if (this._actRep == null)
                {
                    this._actRep = new ActivityRepository(_context);
                }
                return _actRep;
            }
        }

        public RewardTypeRepository RewardTypeRepository
        {
            get
            {
                if (this._rewRep == null)
                {
                    this._rewRep = new RewardTypeRepository(_context);
                }
                return _rewRep;
            }
        }

        public ActivityTypeRepository ActivityTypeRepository
        {
            get
            {
                if (this._actTypeRep == null)
                {
                    this._actTypeRep = new ActivityTypeRepository(_context);
                }
                return _actTypeRep;
            }
        }

        public UserRepository UserRepository
        {
            get
            {
                if (this._usrRep == null)
                {
                    this._usrRep = new UserRepository(_context);
                }
                return _usrRep;
            }
        }

        public UserGroupRepository UserGroupRepository
        {
            get
            {
                if (this._usrGrpRep == null)
                {
                    this._usrGrpRep = new UserGroupRepository(_context);
                }
                return _usrGrpRep;
            }
        }

        public void Commit()
        {
            _context.SaveChanges();
        }

        public void Dispose()
        {
            _context.Dispose();
            GC.SuppressFinalize(_context);
        }

    }

   
}
